﻿using System;

namespace yunio
{
    using yunio._req_ws;
    using yunio.helpers;
    /// <summary>
    /// 轻量websocket
    /// </summary>
    public class YunioWs
    {
        public static IYunioWsClient Listen(string uri, YunioOnMessage on_message)
        {
            var client = new ws_client(uri);
            client.OnMessage += on_message;

            // 连接服务端
            if (!client.Connect()) return default;
            client.StartReceiveLoop();
            return client;
        }
        public static IYunioWsClient Listen(string uri, YunioParam param , YunioOnMessage on_message)
        {
            helper.uri_add_param(ref uri, param);

            var client = new ws_client(uri);
            client.OnMessage += on_message;

            // 连接服务端
            if (!client.Connect()) return default;
            client.StartReceiveLoop();
            return client;
        }
    }
}
